const controller = new AbortController();
const {signal} = controller;

fetch("https://www.baidu.com", {signal})
    .then(r => r.text())
    .then(console.log)
    .catch(err => {
        if (err.name === "AbortError") console.log("请求已取消");
        else console.error("请求出错:", err);
    });

setTimeout(() => controller.abort(), 300);
